//
//  SuperViewController.m
//  TaxDealPlatform
//
//  Created by Zhengtong on 15/4/29.
//  Copyright (c) 2015年 Zhengtong. All rights reserved.
//

#import "SuperViewController.h"

@interface SuperViewController ()<MBProgressHUDDelegate>
{
    UITapGestureRecognizer *_taptohideGesture;
    UIView *statusView ;
    MBProgressHUD *HUD;
}


@end

@implementation SuperViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    
}

#pragma mark - 提示 -成功状态
- (void)success:(NSString *)msg
{
    MBProgressHUD *hud = [MBProgressHUD HUDForView:self.view];
    if (hud)
    {
        hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"37x-Checkmark.png"]];
        hud.mode = MBProgressHUDModeCustomView;
        hud.labelText = msg;
        [hud hide:YES afterDelay:1.0];
    }
    self.MBhud = hud ;

}
//等待状态
- (void)showActivite:(NSString *)msg
{
    [self.MBhud removeFromSuperview];
    self.MBhud = nil ;
    MBProgressHUD *hud;
    if (self.navigationController.view != nil)
    {
        hud = [MBProgressHUD HUDForView:self.navigationController.view];
        
    }else
    {
        hud = [MBProgressHUD HUDForView:self.view];
        
    }
    
    if (!hud)
    {
        hud = [[MBProgressHUD alloc] initWithView:self.view];
    }
    hud.opaque = YES;
    hud.dimBackground = YES;
    hud.square = YES;
    hud.removeFromSuperViewOnHide = TRUE;
    if (self.navigationController.view!=nil)
    {
        [self.navigationController.view addSubview:hud];
        
    }else
    {
        [self.view addSubview:hud];
        
    }
    [hud setLabelText:msg];
    [hud show:YES];
    self.MBhud = hud ;
}
- (void)showHUD:(NSString *)msg
{
    [self.MBhud removeFromSuperview];
    self.MBhud = nil ;
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hud.removeFromSuperViewOnHide = TRUE;
    hud.mode = MBProgressHUDModeText;
    hud.detailsLabelText = msg ;
    hud.detailsLabelFont = [UIFont boldSystemFontOfSize:14];
    [hud show:YES];
    [hud hide:YES afterDelay:1.5f];
    self.MBhud = hud ;
    
}

//方式1.直接在View上show
- (void)myShowHUD:(NSString *)msg
{
HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];

HUD.delegate = self;



//常用的设置

//小矩形的背景色

HUD.color = [UIColor clearColor];//这儿表示无背景

//显示的文字

    HUD.labelText = msg;

//细节文字

    HUD.detailsLabelText = msg;

//是否有庶罩

HUD.dimBackground = YES;

[HUD hide:YES afterDelay:2];



//只显示文字

MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];

hud.mode = MBProgressHUDModeText;

    hud.labelText = msg;

hud.margin = 10.f;

hud.yOffset = 150.f;

hud.removeFromSuperViewOnHide = YES;

[hud hide:YES afterDelay:3];
    
    
    
}
- (void)showProgress:(double)progress
{
    [self.MBhud removeFromSuperview];
    self.MBhud = nil ;
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hud.mode = MBProgressHUDModeDeterminateHorizontalBar;
    hud.removeFromSuperViewOnHide = TRUE;
    hud.progress = progress;
    hud.labelText = [NSString stringWithFormat:@"下载中%0.2f%%",progress*100];
    [hud show:YES];
    [hud hide:YES afterDelay:1.5f];
    self.MBhud = hud ;
}

- (void)showAnimationaIndicator:(NSString *)msg
{
    [self.indicator removeFromSuperview];
    self.indicator = nil;
 
    ZTAnimationIndicator*  indicator = [[ZTAnimationIndicator alloc]initWithFrame:CGRectMake((self.navigationController.view.width- 80)*0.5, (self.navigationController.view.height- 80)*0.5-50, 80, 80)];
    [indicator setLoadText:msg];
    [self.view addSubview:indicator];
    self.indicator = indicator;
}
- (void)showAnimationaIndicator:(NSString *)msg withFrame:(CGRect)frame
{
    [self.indicator removeFromSuperview];
    self.indicator = nil;
    
    ZTAnimationIndicator*  indicator = [[ZTAnimationIndicator alloc]initWithFrame:frame];
    [indicator setLoadText:msg];
    [self.view addSubview:indicator];
    self.indicator = indicator;
}
#pragma mark - 键盘事件 -
- (void)addKeyBoardNotification
{
    [[NSNotificationCenter defaultCenter]
     addObserver:self
     selector:@selector(keyboardWillShow:)
     name:UIKeyboardWillShowNotification
     object:nil];
    
    [[NSNotificationCenter defaultCenter]
     addObserver:self
     selector:@selector(keyboardWillHide:)
     name:UIKeyboardWillHideNotification
     object:nil];
    
}
#pragma mark - 键盘时间处理 -
- (void)keyboardWillShow:(NSNotification *) notification
{
    // 获取键盘高度
    [self.view removeGestureRecognizer:_taptohideGesture];
    
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideKeyboard:)];
    tap.cancelsTouchesInView = YES;
    _taptohideGesture = tap;
    [self.view addGestureRecognizer:tap];
}
- (void)keyBoarHide
{
    
}
- (void)keyboardWillHide:(NSNotification *) notification

{
    for (UITapGestureRecognizer *tap in self.view.gestureRecognizers)
    {
        
        if ([tap isEqual:_taptohideGesture])
            
        {
            [self keyBoarHide];
            [self.view removeGestureRecognizer:tap];
        }
    }
}
- (void)hideKeyboard:(UITapGestureRecognizer *)tap

{
    if ([tap isEqual:_taptohideGesture])
        
    {
        [self keyBoarHide];
        [self.view removeGestureRecognizer:tap];
    }
}

-(void)removeNotification
{
    [[NSNotificationCenter defaultCenter]
     removeObserver:self
     name:UIKeyboardWillShowNotification
     object:nil];
    
    [[NSNotificationCenter defaultCenter]
     removeObserver:self
     name:UIKeyboardWillHideNotification
     object:nil];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

@end
